package cn.gok.oop;

class A{
    //如果没有显示定义构造方法，那么在编译成.class文件时，编译器会自动添加默认无参构造方法
    private int x;
    A(){
        this.x=100;//自定义无参构造函数，对x赋值为100
    }
    public A(int x){
        this.x=x;
    }
    public void test(){
        int y=0;
        y++;
        System.out.println("x="+this.x+"y="+y);
    }
}
class Car{
    private int price;
    private String name;

    public Car(int price, String name) {
        this.price = price;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Car{" +
                "price=" + price +
                ", name='" + name + '\'' +
                '}';
    }

    public void show(){

    }
}
public class 构造函数 {
    public static void main(String[] args) {
//        A a;//类对象的声明
//        //a=new A();
//        a=new A(1000);
//        a.test();
        Car car=new Car(10,"falali");

    }
}
